package com.example.sys2.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys2.common.result.ResultUtils;
import com.example.sys2.common.utlis.EmptyUtils;
import com.example.sys2.entity.Orders;
import com.example.sys2.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenyueyang
 * @since 2023-09-22
 */
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    IOrdersService service;

    @GetMapping("/getList")
    public Object getList(Orders orders, Integer page, Integer limit){
        Page p = new Page<>(page,limit);
        QueryWrapper queryWrapper = new QueryWrapper();
        if(!EmptyUtils.isEmpty(orders.getState())){
            queryWrapper.eq("state",orders.getState());
        }
        queryWrapper.orderByDesc("id");
        Page res = service.page(p, queryWrapper);
        List list = res.getRecords();
        int total = (int)res.getTotal();
        return ResultUtils.returnSuccessLayui(list,total);
    }





}
